<?php

namespace App\Models\Hotel;

use App\Models\Label;
use App\Models\Scopes\DeleteNo;
use Carbon\Carbon;
use App\Models\BaseModel;
use App\Helpers\MoneyHelper;
use App\Format\BaseFormat;

/**
 * App\Models\Hotel\HotelImage
 *
 * @property int $id
 * @property int $hotel_id 酒店ID
 * @property int $type 类型：1酒店图
 * @property int $cat_id 分类ID
 * @property string $image 图片
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property-read Label|null $cat
 * @property-read mixed $faddress
 * @property-read \App\Models\Hotel\Hotel|null $hotel
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage apiBaseQuery($whereParams = [])
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage bgBaseQuery($whereParams = [])
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel paramsQuery($fields, $params = [])
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage query()
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereCatId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereHotelId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereIds($ids = [])
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereImage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|HotelImage whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class HotelImage extends BaseModel
{
    /**
     * Define table name
     *
     * @var string
     */
    protected $table = 'hotel_images';

    /**
     * Define a primary key
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * A property that cannot be batched.
     *
     * @var array
     */
    protected $guarded = ['id'];
    protected $hidden  = ['updated_at'];
    /*********************************************属性格式化***************************************************************/

    /*********************************************设置属性***************************************************************/

    /*********************************************模型操作***************************************************************/
    public function scopeBgBaseQuery($query, $whereParams = [])
    {
        $query->paramsQuery(['hotel_id', 'cat_id']);

        $query->with(['hotel', 'cat']);

        $query->whereHas('hotel');
    }

    public function scopeApiBaseQuery($query, $whereParams = [])
    {
    }

    public static function getForms($fields = [], $type = 'search', $width = '300px')
    {
        $forms = [
            'hotel_id'  => ['title' => '酒店', 'type' => 'select', 'options' => Hotel::select(['id as value', 'name as label'])->get()],
            'cat_id'    => ['title' => '分类', 'type' => 'select', 'options' => Label::hotelPhotoTypeQuery()->select(['id as value', 'name as label'])->get()],
            'type'      => ['type' => 'hidden'],
            'thumbnail' => ['title' => '图片', 'type' => 'image'],
            'sort'      => ['title' => '排序', 'type' => 'number'],
        ];
        return self::handleForms($forms, $fields, $type, $width);
    }
    /*********************************************模型关联***************************************************************/
    // 关联分类
    public function cat()
    {
        return $this->belongsTo(Label::class, 'cat_id', 'id')->withoutGlobalScope(new DeleteNo());
    }

    // 关联酒店
    public function hotel()
    {
        return $this->belongsTo(Hotel::class, 'hotel_id', 'id');
    }
}
